/**
*	@file Utility.cpp
*
*	@brief this header file is defining table structure
*
*	@author li yuchen
*
*	@date 1/28/2011
*/  
#include "Utility.h"
#include <stdlib.h>
#include <windows.h>

vector<int> concurrency_counter;

bool IsDigit(char c)
{
    if(c >= 48 && c <= 57) return true;
	return false;
}

bool IsCharacter(char c){
	if( (c >= 65 && c <= 90) || // A - Z
		(c >= 97 && c <= 122)   // a - z
	  )  return true;
	return false;
}

bool IsText(char c){
	 return (IsDigit(c) || IsCharacter(c)) == 1;
}

int GetPrecedence(TNode* op){
	switch(op->value){
	// put precedence of ( low in order to make other operator
	// can sit on the top of it on the stack
	case '(':
		return 1;
	// actually the number does not matters
	case ')':
		return 100;
	case '+':
	case '-':
		return 2;
	case '*':
		return 3;
	}
	return -1;
}

int EvalueExpr(TNode* root){
	if(root->child == NULL) return root->value;
	int result1 = EvalueExpr(root->child);
	int result2 = EvalueExpr(root->child->right_sibling);
	switch(root->value){
	case '+':
		return result1+result2;
	case '-':
		return result1-result2;
	case '*':
		return result1*result2;
	}
	return -1;
}

int GetNumCPUs(){
	SYSTEM_INFO m_si = {0, };
	GetSystemInfo(&m_si);
	return (int)m_si.dwNumberOfProcessors;
}

